package com.yonglian.web.controller.system;

import java.util.List;

import com.yonglian.system.domain.CmsProjectType;
import com.yonglian.system.service.ICmsProjectTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yonglian.common.annotation.Log;
import com.yonglian.common.enums.BusinessType;
import com.yonglian.system.domain.CmsProjectBase;
import com.yonglian.system.service.ICmsProjectBaseService;
import com.yonglian.common.core.controller.BaseController;
import com.yonglian.common.core.domain.AjaxResult;
import com.yonglian.common.utils.poi.ExcelUtil;
import com.yonglian.common.core.page.TableDataInfo;

/**
 * 项目基础信息Controller
 *
 * @author gyok
 * @date 2024-05-28
 */
@Controller
@RequestMapping("/system/projectBase")
public class CmsProjectBaseController extends BaseController
{
    private String prefix = "system/projectBase";

    @Autowired
    private ICmsProjectBaseService cmsProjectBaseService;

    @Autowired
    private ICmsProjectTypeService cmsProjectTypeService;

    @RequiresPermissions("system:projectBase:view")
    @GetMapping()
    public String projectBase(Model model)
    {
        List<CmsProjectType> typeList = cmsProjectTypeService.selectCmsProjectTypeList(null);
        model.addAttribute("typeList", typeList);
        return prefix + "/projectBase";
    }

    /**
     * 查询项目基础信息列表
     */
    @RequiresPermissions("system:projectBase:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsProjectBase cmsProjectBase)
    {
        startPage();
        List<CmsProjectBase> list = cmsProjectBaseService.selectCmsProjectBaseList(cmsProjectBase);
        return getDataTable(list);
    }

    /**
     * 导出项目基础信息列表
     */
    @RequiresPermissions("system:projectBase:export")
    @Log(title = "项目基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsProjectBase cmsProjectBase)
    {
        List<CmsProjectBase> list = cmsProjectBaseService.selectCmsProjectBaseList(cmsProjectBase);
        ExcelUtil<CmsProjectBase> util = new ExcelUtil<CmsProjectBase>(CmsProjectBase.class);
        return util.exportExcel(list, "项目基础信息数据");
    }

    /**
     * 新增项目基础信息
     */
    @GetMapping("/add")
    public String add(Model model)
    {
        List<CmsProjectType> typeList = cmsProjectTypeService.selectCmsProjectTypeList(null);
        model.addAttribute("typeList", typeList);
        return prefix + "/add";
    }

    /**
     * 新增保存项目基础信息
     */
    @RequiresPermissions("system:projectBase:add")
    @Log(title = "项目基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsProjectBase cmsProjectBase)
    {
        return toAjax(cmsProjectBaseService.insertCmsProjectBase(cmsProjectBase));
    }

    /**
     * 修改项目基础信息
     */
    @RequiresPermissions("system:projectBase:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsProjectBase cmsProjectBase = cmsProjectBaseService.selectCmsProjectBaseById(id);
        List<CmsProjectType> typeList = cmsProjectTypeService.selectCmsProjectTypeList(null);
        mmap.addAttribute("typeList", typeList);
        mmap.put("cmsProjectBase", cmsProjectBase);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目基础信息
     */
    @RequiresPermissions("system:projectBase:edit")
    @Log(title = "项目基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsProjectBase cmsProjectBase)
    {
        return toAjax(cmsProjectBaseService.updateCmsProjectBase(cmsProjectBase));
    }

    /**
     * 删除项目基础信息
     */
    @RequiresPermissions("system:projectBase:remove")
    @Log(title = "项目基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsProjectBaseService.deleteCmsProjectBaseByIds(ids));
    }
}
